package com.xinyi.tangmi;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xinyi.tangmi.R;

public class MenuFragment extends Fragment {
	protected static final int CLASS_CMP = 0;
	Handler handler;
	int lasty;
	final int touchEventId = 265;
	TextView man;
	TextView woman;
	TextView kid;
	ImageView scrollBar;
	static float leftMatgin = 0;
	float lastx = 0;
	Context context;

	@SuppressLint("NewApi")
	@Override
	public View onCreateView(LayoutInflater inflater,
			final ViewGroup container, Bundle savedInstanceState) {
		final View view = inflater.inflate(R.layout.layout_menu, null);
		context = container.getContext();
		handler = new Handler() {

			public void handleMessage(android.os.Message msg) {
				switch (msg.what) {
				case CLASS_CMP:
					setView(view);
					break;
				case touchEventId:
					break;

				default:
					break;
				}

			};
		};

		OnClickListener onClickListener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switch (v.getId()) {

				default:
					break;
				}
			}
		};
		return view;
	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		handler.postDelayed(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				handler.sendEmptyMessage(CLASS_CMP);
			}
		}, 300);
	}

	@SuppressLint("NewApi")
	public void setView(View parent) {
		OnClickListener onClickListener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(context, ItemListActivity.class);
				switch (v.getId()) {
				case R.id.class1:
					intent.putExtra("url", "13");
					break;
				case R.id.class2:
					intent.putExtra("url", "12");
					break;
				case R.id.class3:
					intent.putExtra("url", "64");
					break;
				case R.id.class4:
					intent.putExtra("url", "66");
					break;
				case R.id.class5:
					intent.putExtra("url", "67");
					break;
				case R.id.class6:
					intent.putExtra("url", "71");
					break;
				case R.id.class7:
					intent.putExtra("url", "68");
					break;
				case R.id.class8:
					intent.putExtra("url", "69");
					break;
				case R.id.class9:
					intent.putExtra("url", "70");
					break;
				case R.id.class10:
					intent.putExtra("url", "35");
					break;
				case R.id.class11:
					intent.putExtra("url", "31");
					break;
				case R.id.class12:
					intent.putExtra("url", "75");
					break;
				case R.id.class13:
					intent.putExtra("url", "32");
					break;
				case R.id.class14:
					intent.putExtra("url", "34");
					break;
				case R.id.class15:
					intent.putExtra("url", "74");
					break;
				case R.id.class16:
					intent.putExtra("url", "72");
					break;
				case R.id.class17:
					intent.putExtra("url", "73");
					break;
				case R.id.class19:
					intent.putExtra("url", "63");
					break;
				case R.id.class20:
					intent.putExtra("url", "61");
					break;
				case R.id.class21:
					intent.putExtra("url", "60");
					break;
				case R.id.class22:
					intent.putExtra("url", "77");
					break;
				case R.id.class23:
					intent.putExtra("url", "62");
					break;
				case R.id.class24:
					intent.putExtra("url", "76");
					break;

				default:
					break;
				}
				// MainActivity.handler.sendEmptyMessage(0);
				startActivityForResult(intent, ContentFragment.REQUEST_IMGURL);
			}
		};
		CircleImageView manCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class1);
		manCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				manCircleImageView.getWidth(), manCircleImageView.getWidth()));
		CircleImageView womanCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class2);
		womanCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				womanCircleImageView.getWidth(), womanCircleImageView
						.getWidth()));
		CircleImageView kidImageView = (CircleImageView) parent
				.findViewById(R.id.class3);
		kidImageView.setLayoutParams(new LinearLayout.LayoutParams(kidImageView
				.getWidth(), kidImageView.getWidth()));
		manCircleImageView.setOnClickListener(onClickListener);
		womanCircleImageView.setOnClickListener(onClickListener);
		kidImageView.setOnClickListener(onClickListener);
		manCircleImageView = (CircleImageView) parent.findViewById(R.id.class4);
		womanCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class5);
		kidImageView = (CircleImageView) parent.findViewById(R.id.class6);
		manCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		womanCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		kidImageView.setLayoutParams(new LinearLayout.LayoutParams(kidImageView
				.getWidth(), kidImageView.getWidth()));
		manCircleImageView.setOnClickListener(onClickListener);
		womanCircleImageView.setOnClickListener(onClickListener);
		kidImageView.setOnClickListener(onClickListener);
		manCircleImageView = (CircleImageView) parent.findViewById(R.id.class7);
		womanCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class8);
		kidImageView = (CircleImageView) parent.findViewById(R.id.class9);
		manCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		womanCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		kidImageView.setLayoutParams(new LinearLayout.LayoutParams(kidImageView
				.getWidth(), kidImageView.getWidth()));
		manCircleImageView.setOnClickListener(onClickListener);
		womanCircleImageView.setOnClickListener(onClickListener);
		kidImageView.setOnClickListener(onClickListener);
		manCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class10);
		womanCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class11);
		kidImageView = (CircleImageView) parent.findViewById(R.id.class12);
		manCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		womanCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		kidImageView.setLayoutParams(new LinearLayout.LayoutParams(kidImageView
				.getWidth(), kidImageView.getWidth()));
		manCircleImageView.setOnClickListener(onClickListener);
		womanCircleImageView.setOnClickListener(onClickListener);
		kidImageView.setOnClickListener(onClickListener);
		manCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class13);
		womanCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class14);
		kidImageView = (CircleImageView) parent.findViewById(R.id.class15);
		manCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		womanCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		kidImageView.setLayoutParams(new LinearLayout.LayoutParams(kidImageView
				.getWidth(), kidImageView.getWidth()));
		manCircleImageView.setOnClickListener(onClickListener);
		womanCircleImageView.setOnClickListener(onClickListener);
		kidImageView.setOnClickListener(onClickListener);
		manCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class16);
		womanCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class17);
		kidImageView = (CircleImageView) parent.findViewById(R.id.class18);
		manCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		womanCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		kidImageView.setLayoutParams(new LinearLayout.LayoutParams(kidImageView
				.getWidth(), kidImageView.getWidth()));
		manCircleImageView.setOnClickListener(onClickListener);
		womanCircleImageView.setOnClickListener(onClickListener);
		manCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class19);
		womanCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class20);
		kidImageView = (CircleImageView) parent.findViewById(R.id.class21);
		manCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		womanCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		kidImageView.setLayoutParams(new LinearLayout.LayoutParams(kidImageView
				.getWidth(), kidImageView.getWidth()));
		manCircleImageView.setOnClickListener(onClickListener);
		womanCircleImageView.setOnClickListener(onClickListener);
		kidImageView.setOnClickListener(onClickListener);
		manCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class22);
		womanCircleImageView = (CircleImageView) parent
				.findViewById(R.id.class23);
		kidImageView = (CircleImageView) parent.findViewById(R.id.class24);
		manCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		womanCircleImageView.setLayoutParams(new LinearLayout.LayoutParams(
				kidImageView.getWidth(), kidImageView.getWidth()));
		kidImageView.setLayoutParams(new LinearLayout.LayoutParams(kidImageView
				.getWidth(), kidImageView.getWidth()));
		manCircleImageView.setOnClickListener(onClickListener);
		womanCircleImageView.setOnClickListener(onClickListener);
		kidImageView.setOnClickListener(onClickListener);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		if (resultCode == ContentFragment.RESULT_IMGURL) {
			FragmentManager fragmentManager = getActivity()
					.getSupportFragmentManager();
			ContentFragment contentFragment = (ContentFragment) fragmentManager
					.findFragmentById(R.id.content_frame);
			if (contentFragment != null) {
				contentFragment.imageTouchViews.add(new ImageTouchView(
						getActivity(), data.getStringExtra("img_url"),
						contentFragment.drawHandler,
						contentFragment.imageTouchViews.size()));
			}

			Log.i("data", data.toString() + data.getStringExtra("img_url"));
		}
		super.onActivityResult(requestCode, resultCode, data);
	}
}
